<template>
  <el-dialog title="导入Excel" :visible.sync="dialogFormVisible" :close-on-click-modal='false' center append-to-body>
    <el-button class="miui-dialog-close-btn" @click="dialogFormVisible = false">关闭页面</el-button>
    <el-upload
      class="upload-demo"
      action="/pvm/student/upload"
      :headers="headers"
      :data="{'fromYear': fromYear,'toYear':toYear}"
      :on-success="successHandle"
      :on-error="errorHandle"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :before-remove="beforeRemove"
      multiple
      :file-list="fileList">
      <el-button size="small" type="primary">点击上传</el-button>
    </el-upload>
  </el-dialog>
</template>

<script>
  import store from '@/store'
  export default {
    props: ['fromYear','toYear'],
    data(){
      return {
        headers: {
            'Authorization': 'Bearer ' + store.getters.access_token,
        },
        uploadParams:{},
        dialogFormVisible: false,
        fileList: []
      }
    },
    methods:{
      init(){
        this.dialogFormVisible = true
      },
      successHandle(response, file, fileList){
        if(response.code == '0'){
          this.$message.success('上传成功')
        }else{
          this.$message.error(response.msg)
        }
      },
      errorHandle(err, file, fileList){
        this.$message.error(err)
      },
      handlePreview(file) {
        console.log(file);
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }？`);
      },
      handleRemove(){

      }
    }
  }
</script>

<style>
</style>
